#pragma once
#include <iostream>
#include <string>
#include <unordered_map>
#include <fstream>
#include "Log.hpp"
#include "LockGuard.hpp"
using namespace log_ns;

const std::string gconfig = "Dictionary.txt";
class dict_t
{
private:
    void Load()
    {
        EnableFile();
        std::ifstream in(_config.c_str());
        std::string tmp;
        std::string key;
        std::string value;
        while (getline(in, tmp))
        {
            if (tmp == "")
                continue;
            int pos = tmp.find(": ");
            if (pos == 0 || pos == std::string::npos)
                continue;
            key = tmp.substr(0, pos);
            value = tmp.substr(pos + 2);
            if (key == "" || value == "")
                continue;
            _dict[key] = value;
        }

        LOG(INFO, "Dict Load done\n");

    }

public:
    dict_t(std::string config = gconfig) : _config(config)
    {
        Load();
    }

    std::string translation(std::string key)
    {
        if (key == "")
            return "None";
        if (_dict.find(key) != _dict.end())
        {
            return _dict[key];
        }
        return "None";
    }

private:
    std::unordered_map<std::string, std::string> _dict;
    std::string _config;
};